package com.lj.controller;

import com.lj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String loginControl(String username,String password){
        String loginSuccess = userService.loginService(username, password);
        System.out.println(loginSuccess);
//        if(loginSuccess){
//            return "redirect:success.html";
//        }
//        return "redirect:login.html";
        return loginSuccess;
    }

    @RequestMapping("/register")
    public String registerControl(String username, String password){
        userService.registerService(username, password);

        return "注册成功";
    }


    @RequestMapping("/getUsers")
    public List<Map<String,Object>> getUsers(){
        String sql = "SELECT * from user";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
}
